<?php

namespace app\http\controller;

use tmcore\services\wechat\WxOaService;

class Wechat extends HttpController
{
    /**
     * 微信公众号实例
     * @var WxOaService
     */
    protected WxOaService $wechatService;

    /**
     * 初始化方法
     */
    public function initialize()
    {
        $this->wechatService = (new WxOaService);
    }

    /**
     * 微信公众号授权
     * @return \think\Response
     * @throws \EasyWeChat\Kernel\Exceptions\BadRequestException
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
     * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
     * @throws \ReflectionException
     * @throws \Throwable
     */
    public function auth() {
        $server = $this->wechatService->getServer();
        return response($server->serve()->getBody())->header([
            'Content-Type' => 'text/plain;charset=utf-8'
        ]);
    }
}